package com.example.demo.controller;

import com.example.demo.model.UserInfo;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/getuserbyid")
    public UserInfo getUserById(Integer id) {
        if(id == null) return null;
        return userService.getUserById(id);
    }

    @RequestMapping("/login")
    public String login(String username,String password) {
        if(StringUtils.hasLength(username) || StringUtils.hasLength(password)) {
            if(userService.login(username,password) != null) {
                return "登陆成功";
            }
        }
        return "登陆失败";
    }

}
